﻿using System.Collections.Generic;
using System.ComponentModel;
using PersonaLibrary.ViewModel.SearchViewModel;

namespace PersonaLibrary.Search
{
	public class SearchItemModel : INotifyPropertyChanged
	{
		private readonly List<string> _binaryOperators = new List<string> { "ИЛИ", "И" };
		private List<SearchCriteria> _properties = new List<SearchCriteria>();
		private string _selectedBinaryOperator;
		private SearchCriteria _selectedProperty;
		private bool _binaryEnable = true;
		private string _value;

		public string Value
		{
			get { return _value; }
			set
			{
				_value = value;
				RisePropertyChanged("Value");
			}
		}

		public bool BinaryEnable
		{
			get { return _binaryEnable; }
			set
			{
				_binaryEnable = value;
				RisePropertyChanged("BinaryEnable");
			}
		}

		public string SelectedBinaryOperator
		{
			set
			{
				_selectedBinaryOperator = value;
				RisePropertyChanged("SelectedBinaryOperator");
			}
			get
			{
				return _selectedBinaryOperator;
			}
		}
		
		public List<string> BinaryOperators
		{
			get
			{
				return _binaryOperators;
			}
		}

		public SearchCriteria SelectedProperty
	    {
	        set 
            { 
                _selectedProperty = value;
                RisePropertyChanged("SelectedProperty");
            }
            get { return _selectedProperty; }
	    }

		public List<SearchCriteria> Properties
		{
			get { return _properties; }

			set
			{
				_properties = value;
				if(_properties != null && _properties.Count > 0)
				{
					_selectedProperty = _properties[0];
					_selectedProperty.Operator = _selectedProperty.Operators[0];
				}
			}
		}

		public event PropertyChangedEventHandler PropertyChanged;

		protected void RisePropertyChanged(string propertyName)
		{
			if (PropertyChanged != null) 
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
		}
	}
}
